import datetime
import random

global tanklevel
tanklevel = 0
global  tmp
tmp=0
def openValveState(flag):
    if flag==1:
        ValveState = 1
    else :
        ValveState = 0
    return str(ValveState)

# 开阀液位上升，关阀液位下降
# 还有液位上升 （下降）基本保证是一条直线
def tanklevelValue():
    h = int((datetime.datetime.now()).strftime("%H"))
    global tanklevel
    global  tmp

    if tanklevel>=4:
        tmp = tanklevel

    if tmp>=4 and tanklevel>=1 :
        valveState =openValveState(0)
        tanklevel=tanklevel-0.001
        if tanklevel==1:
            tmp=0
    else :
        tanklevel = tanklevel + 0.01
        valveState =openValveState(1)

    # if (h>=6 and h<=9) or (h>=11 and h<=14)or(h>=17 and h<=22) :
    #     if tanklevel>=4:
    #         tanklevel=tanklevel-0.005
    #         valveState =openValveState(0)
    #     else:
    #         tanklevel = tanklevel + 0.01
    #         valveState =openValveState(1)
    # else :
    #     if tanklevel>=4:
    #         tanklevel=tanklevel-0.005
    #         valveState =openValveState(0)
    #     else:
    #         tanklevel = tanklevel + 0.01
    #         valveState =openValveState(1)

    print("--------tanklevel---------"+str(tanklevel))
    print("--------valveState---------"+str(valveState))
    return {"tanklevel":str(tanklevel),"valveState":str(valveState)}

# for num in range(0,10):
#    tanklevelValue()